home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2218 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  687 b 

  1. Path: newsbf02.news.aol.com!not-for-mail
  2. From: babycox@aol.com (BabyCox)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: quick decision: is n a power of 2?
  5. Date: 19 Jan 1996 17:19:32 -0500
  6. Organization: America Online, Inc. (1-800-827-6364)
  7. Sender: root@newsbf02.news.aol.com
  8. Message-ID: <4dp5dk$t3r@newsbf02.news.aol.com>
  9. References: <4dorr8$i58@cloner3.netcom.com>
  10. Reply-To: babycox@aol.com (BabyCox)
  11. NNTP-Posting-Host: newsbf02.mail.aol.com
  12.  
  13.  
  14. >#define ISPOW2(x) (((x) & 1) ^ 1)
  15.  
  16. That will not work, it returns the next lowest MULTIPLE of two, here's
  17. what I would do:
  18.  
  19. Boolean IsPowerOfTwo(long x)
  20. {
  21.   for(short y = 0;y<=31;y++)
  22.   {
  23.     if (x = 1) return true;
  24.     x >>= 1;
  25.   }
  26.   return false;
  27. }
  28.